local Badge = require "widgets/badge"
local UIAnim = require "widgets/uianim"

local Musha_FatigueSleepBadge =
	Class(
	Badge,
	function(self, owner)
		Badge._ctor(self, "musha_fatiguesleep", owner, {174 / 255, 21 / 255, 21 / 255, 1}, nil)

		self.musha_fatiguesleeparrow = self.underNumber:AddChild(UIAnim())
		self.musha_fatiguesleeparrow:GetAnimState():SetBank("sanity_arrow")
		self.musha_fatiguesleeparrow:GetAnimState():SetBuild("sanity_arrow")
		self.musha_fatiguesleeparrow:GetAnimState():PlayAnimation("neutral")
		self.musha_fatiguesleeparrow:SetClickable(false)

		self:StartUpdating()
	end
)

function Musha_FatigueSleepBadge:SetPercent(val, max)
	Badge.SetPercent(self, val, max)
end

function Musha_FatigueSleepBadge:OnUpdate(dt)
	local anim = "neutral"
	if
		self.owner ~= nil and self.owner:HasTag("sleeping") and self.owner.replica.hunger ~= nil and
			self.owner.replica.hunger:GetPercent() > 0
	 then
		anim = "arrow_loop_increase"
	end

	--[[ if self.owner.components.debuffable and self.owner.components.debuffable:HasDebuff("wintersfeastbuff") then
		anim = "arrow_loop_increase"
	end ]]
	if self.arrowdir ~= anim then
		self.arrowdir = anim
		self.musha_fatiguesleeparrow:GetAnimState():PlayAnimation(anim, true)
	end
end

return Musha_FatigueSleepBadge
